
#pragma once
#include "OgreOggSound.h"
#include "sound.h"
namespace Ogitors
{
	class LightVisualHelper;

	class   CSoundEditor: public CBaseEditor , public iSoundEditor
	{
		friend class CSoundEditorFactory;
	public:
		virtual void            Attach(CBaseEditor *parent);
		virtual void            Detach();
		virtual bool			SetupPropertiesWnd();
		virtual bool            Update(float timePassed);
		virtual void            GetObjectProperties(Ogre::NameValuePairList &retList);
		virtual bool            HandleCustomFunction(int BIND_ID, Ogre::String val);
		void					SetHandle(OgreOggSound::OgreOggISound * objHandle);
		virtual void			SetHandle(void *objHandle,bool display);
		virtual void            SetHelper(CVisualHelper *objHelper);
		virtual void            SetSelected(bool bSelected);
		virtual void            FreeHandle();
		/// Overridden by Editor Objects to Import Object Dependant Properties
		virtual CBaseEditor    *Restore(Ogre::NameValuePairList &retList);
		/// Gets the Handle to encapsulated object
		inline virtual void    *GetHandle() {return static_cast<void*>(m_Handle);};
		/// Returns the Factory associated with this object
		static CBaseEditorFactory *GetFactory();
		/// Returns the Factory associated with this object can be overridden
		virtual CBaseEditorFactory *GetFactoryDynamic();
		virtual Ogre::AxisAlignedBox GetAABB() {if(m_Helper) return m_Helper->GetAABB(); else return Ogre::AxisAlignedBox::BOX_NULL;};

		virtual Ogre::Vector3	GetPosition() 
		{
			return m_Handle->getParentSceneNode()->getPosition();
		};

		virtual Ogre::Vector3	GetDirection() {return m_Handle->getDirection();};

		virtual Ogre::Quaternion GetDerivedOrientation();
		virtual Ogre::Quaternion GetOrientation();

		/// Gets Object's Cast Shadows Property 
		virtual bool			GetCastShadows() {return m_Handle->getCastShadows();};


		// This function is a general purpose function to set derived position of an object
		virtual void			SetDerivedPosition(Ogre::Vector3 val,bool refresh);
		virtual void			SetPosition(int BIND_ID,Ogre::Vector3 val,bool refresh);

		virtual void			SetOrientation(int BIND_ID,Ogre::Quaternion val,bool refresh);
		void                    SetOrientation(Ogre::Quaternion val) {m_Orientation = val;UpdateHelper();}

		virtual void            SetCastShadows(int BIND_ID,Ogre::String val,bool refresh);

		virtual void		 	GetObjectUserData(std::ofstream &outfile);

		void                   	SetPos(int pos);
		int                     getPos () ;
		float                   getPlayPos();

		void                    play() ;
		void                    stop() ;
		void                    pause() ;
		bool					isplay() ;
		Ogre::String			getName() ;
	protected:

		Ogre::String m_MusicFile;

		void FindMusicFile( Ogre::StringVector & soundList,const Ogre::String &path = "..\\Media\\avatar\\sound\\*.ogg");
		OgreOggSound::OgreOggISound *m_Handle;
		//Ogre::Light *m_Handle;
		Ogre::Quaternion m_Orientation;
		LightVisualHelper* m_LightVisualHelper;


		CSoundEditor(Ogre::String typestring = "SoundObject",EDITORTYPE etype = ETYPE_LIGHT);
		virtual                ~CSoundEditor();

		void                  ChanageSound(const Ogre::String & ogg);
		virtual void			 UpdateHelper();
		void                  CalculateOrientation();
	};

	class   CSoundEditorFactory: public CBaseEditorFactory
	{
	public:
		CSoundEditorFactory() {};
		virtual ~CSoundEditorFactory() {};
		virtual CBaseEditor *CreateObject(CBaseEditor **parent, Ogre::NameValuePairList &params);
	};
}
